<script setup lang="ts">

import { Form } from '@/components/Form'
import { useForm } from '@/hooks/web/useForm'
import { PropType, reactive, watch } from 'vue'
import { TableData } from '@/api/table/types'
import { useValidator } from '@/hooks/web/useValidator'
import { FormSchema } from '@/types/form'
const { required } = useValidator()
const props = defineProps({
  currentRow: {
    default: () => null
  },
  formSchema: {
    type: Array as PropType<FormSchema[]>,
    default: () => []
  }

})
const { register, methods, elFormRef } = useForm({
  schema: props.formSchema
})
watch(
  () => props.currentRow,
  (currentRow) => {
    if (!currentRow) return
    const { setValues } = methods
    setValues(currentRow)
  },
  {
    deep: true,
    immediate: true
  }
)
defineExpose({
  elFormRef,
  getFormData: methods.getFormData
})
const rules = reactive({
  coupon_name: [required()],
  couponType: [required()],
  couponPrice: [required()],
  start_date: [required()],
  end_date: [required()],
  online: [required()],
  mode: [required()],
  type: [required()],
  issue_quantity: [required()],
})
</script>
<template>
    <Form :rules="rules" @register="register" />
</template>